1 TREES - TREES - TREES

1.1 Introduction

Sustainability offers a variety of challenges and opportunities in regard to data science. More and more data is available from around the global in regards to sustainability and each regions has its on challenges with sustainability. However, for this project we will focus on a problem that is more local to us. We are going to analyse the impact trees have on our everyday lives in regards to temperature and air quality.

1.2 Goal of the project:

We would like to prove that the planting of trees and the development of green spaces in an urban environment have positive correlations with the development of air quality indicators and a negative impact on temperatures in the city of Zurich. This project will try to pinpoint the effect trees have on these indicators. The results will be presented in a way to inform politicians, urban developers as well as the public about the impact that a more green city could have on our everyday lives. While there are a number of potential factors, both local and national/global, can have a significant impact on the climate and for this research we are choosing to focus on data from Zürich in regards to air quality, temperature information and the tree inventory. Further factors are described using sources, but are not included in the data analysis.

1.3 Big Picture: Embedding in the Sustainable Development Goals (SDG)

The SDGs lay out the goals that the global community has agreed on. Total there are 17 goals and they range from 1. No poverty to 17. Partnerships for the goals and include social, economic and environmental targets. For the research we have identified the relevant goals and put them into the three different categories: Risk, Opportunity and Intended. Sustainable Development Goals As can be seen the intended target for our research is to help achieve the goal number 3. Good health and well being. This can be achieved if we can prove a correlation between the amount of trees in a region and an improvement in air quality, which could then lead to increase of planting of new trees in Zürich as well as a reduction of concrete wastelands in favor of green spaces. There are a number opportunities as well in regards to climate action, economic growth and affordable and clean energy. The are only limited risks that this project has. However it is imaginable that the improvement in air quality in certain areas could lead to a increase in inequalities between the rich and poor. It is also important to always be responsible and think of possible unintended consequences while planning for new green zones and planting new trees.

1.4 Data sources

For the research there are three different data sets needed: Air quality information, temperature data, and a tree cadastre. All of these three data sets are publicly available. Following is a quick overview over the different data sets:

1.4.1 Air quality

Format: csv
Number of rows: 283’763
Number of variables: 8 (most important: date, location, type of measurement, value)
Source: https://data.stadt-zuerich.ch/dataset/ugz_luftschadstoffmessung_stundenwerte

1.4.2 Meteo

Format: csv
Number of rows: 4’747
Number of variables: 17 (most important: date, temperature, location)
Source: https://opendata.swiss/de/dataset/taglich-aktualisierte-meteodaten-seit-1992

1.4.3 Tree cadastre

Format: csv
Number of rows: 36’239
Number of variables: 17 (most important: year of planting, diameter of crown, district)
Source: https://data.stadt-zuerich.ch/dataset/geo_baumkataster

1.5 Importing all packages and libraries

The following libraries were used to analyse the data:

1.6 Data preparation

In this step we collected the three data sets and prepared them so that they are for use in the analysis. To achieve this, certain changes to the data were necessary to facilitate an informative analysis.

First we loaded the tree cadastre data and wrangled the data to get additional information such as the amount of trees per year and the number of trees by district.

d.trees <- read.csv('../datasets/gsz.baumkataster_baumstandorte.csv', encoding = "UTF-8")
names(d.trees)[1] <- "objid" 
#head(trees)
#str(trees)


#Wrangling and mutating tree data

# trees by year
tree_ts <- d.trees %>%
  dplyr::select(pflanzjahr) %>%
  filter(pflanzjahr > 1980) %>%
  group_by(pflanzjahr) %>%
  summarise(count = n())

# Trees by district
tree_quartier <- d.trees %>%
  dplyr::select(pflanzjahr, objid, quartier) %>%
  filter(pflanzjahr > 1980) %>%
  group_by(pflanzjahr, quartier) %>%
  summarise(count = n())
## `summarise()` has grouped output by 'pflanzjahr'. You can override using the
## `.groups` argument.
# sum of trees
tree_ts_sum <- tree_ts %>%
 mutate(sum_trees = cumsum(count))


# Trees by district, year
tree_quartier_year_full <- d.trees %>%
  dplyr::select(pflanzjahr, quartier, kronendurchmesser) %>%
  filter(pflanzjahr > 1980) %>%
  group_by(pflanzjahr, quartier) %>%
  summarise(count = n(), sum_crown = sum(kronendurchmesser))
## `summarise()` has grouped output by 'pflanzjahr'. You can override using the
## `.groups` argument.
# trees by year
tree_year <- d.trees %>%
  dplyr::select(pflanzjahr, kronendurchmesser) %>%
  filter(pflanzjahr > 1980) %>%
  group_by(pflanzjahr) %>%
  summarise(tree_count = n(), crown_sum = sum(kronendurchmesser))

tree_year_sum <- tree_year %>%
  mutate(cum_trees = cumsum(tree_count)) %>%
  mutate(cum_crown = cumsum(crown_sum))

Next we load all the temperature information from the meteo data set. While this data set includes other information such as rain duration we will only use the temperature, as it seems unlikely that the amount of trees significantly impact the rain fall in an area.

filenames.meteo <- list.files(path = "../datasets/meteo/", pattern = "*.csv", full.names = TRUE)
data_list.meteo <- lapply(filenames.meteo, read.csv)
# Combine the data frames in the list into a single data frame
meteo <- do.call(rbind, data_list.meteo)

names(meteo)[1] <- "Date"
meteo$Date <- format(as.Date(meteo$Date), format = "%Y-%m-%d")

# Datensatz mit Temperatur und Globalstrahlung pro Messstation
meteo.extr <- meteo %>%
  filter(Parameter == "T" | Parameter == "StrGlo" | Parameter =="T_max_h1")
meteo.extr$Jahr <- year(meteo.extr$Date)

# weiter mit "normalem" Meteodatensatz
meteo <- meteo[meteo$Standort=="Zch_Stampfenbachstrasse",]
meteo <- meteo %>% 
  select(c("Date","Parameter","Wert")) %>%
  pivot_wider(id_cols = "Date",names_from = "Parameter",values_from = "Wert") %>%
  select(c("Date","T","RainDur","p"))

meteo$Date <- ymd(meteo$Date)

head(meteo)

Lastly the air quality data is loaded. While there are multiple location were air quality was measured not every station measured each variable. They also were not all built at the same time.

filenames.air <- list.files(path = "../datasets/air/", pattern = "*.csv", full.names = TRUE)
data_list.air <- lapply(filenames.air, read.csv)
# Combine the data frames in the list into a single data frame
air <- do.call(rbind, data_list.air)
names(air)[1] <- "Date"
air$Date <- as.Date(format(air$Date), "%Y-%m-%d")
# add column Jahr
air$Jahr <- as.numeric(format(air$Date,'%Y'))
head(air)
air.wide <- air %>% 
  filter(Standort == "Zch_Stampfenbachstrasse") %>%
  select(c("Date", "Parameter", "Wert")) %>%
  pivot_wider(id_cols = "Date", names_from = "Parameter", values_from = "Wert")

air.short <- air[air$Standort=="Zch_Stampfenbachstrasse",]

air.short <- air.short %>%
  select(c("Date", "Parameter", "Wert")) %>%
  pivot_wider(id_cols = "Date",names_from = "Parameter",values_from = "Wert")

keep <- c("Date", "CO", "NOx")
air.short <- air.short[keep]
keep <- c("Date", "CO")
air.co <- air.short[keep]
keep <- c("Date", "NOx")
air.NOx <- air.short[keep]
#air.NOx <- air["NOx"] <- log(air["NOx"])

1.7 Insights into our datasets

To gain insights from the available information we have created a number of graphics. These already show preliminary results of our project.

#melt data frame into long format
air.plot <- melt(air.co,  id.vars = "Date")
#create line plot for each column in data frame
ggplot(air.plot, aes(Date, value), group = 5) +
  geom_line(aes(colour = variable))

air.means = air %>% 
  filter(!is.na(Wert)) %>% 
  group_by(Parameter, Jahr) %>%
  summarize(Mean = round(mean(Wert),2),
            .groups = "drop")
plot(subset(air.means, Parameter == "CO", 
            c(Jahr, Mean)), type = "l",
     main = "Mean of CO per Year [mg/m3]")  

plot(subset(air.means, Parameter == "NO", 
            c(Jahr, Mean)), type = "l",
     main = "Mean of NO per Year [µg/m3]")

plot(subset(air.means, Parameter == "NO2", 
            c(Jahr, Mean)), type = "l",
     main = "Mean of NO2 per Year [µg/m3]")

plot(subset(air.means, Parameter == "NOx", 
            c(Jahr, Mean)), type = "l",
     main = "Mean of NOx per Year [ppb]")

plot(subset(air.means, Parameter == "O3", 
            c(Jahr, Mean)), type = "l",
     main = "Mean of O3 per Year [µg/m3]") 

plot(subset(air.means, Parameter == "O3_max_h1",
            c(Jahr, Mean)), type = "l",
     main = "Mean of O3_max_h1 per Year [µg/m3]") 

plot(subset(air.means, Parameter == "O3_nb_h1>120",
            c(Jahr, Mean)), type = "l",
     main = "Mean of O3_nb_h1>120 per Year [1]") 

plot(subset(air.means, Parameter == "PM10",
            c(Jahr, Mean)), type = "l",
     main = "Mean of PM10 per Year [mg/m3]") 

plot(subset(air.means, Parameter == "PM2.5",
            c(Jahr, Mean)), type = "l",
     main = "Mean of PM2.5 per Year [mg/m3]") 

plot(subset(air.means, Parameter == "PN",
            c(Jahr, Mean)), type = "l",
     main = "Mean of PN per Year [1/cm3]") 

plot(subset(air.means, Parameter == "SO2",
            c(Jahr, Mean)), type = "l",
     main = "Mean of SO2 per Year [µg/m3]")

One can see that the both the “NOx” and the “CO” graph show that the air quality has improved significantly since 1980. It is unlikely to say the least that trees are the only factor in this improvement. More likely other factors such as new laws and regulations in regards to catalysts of cars are more likely the major factor.

# Boxplots for CO all over Zürich
boxplot(Wert ~ Jahr, data = air, subset = Parameter %in% names(table("CO")),
        main= "CO in Zürich (Stampfenbachstrasse) per Year [mg/m3]",
        xlab = "Year", ylab = "mg/m3")

boxplot(Wert ~ Jahr, data = air, subset = Parameter %in% names(table("NOx")),
        main= "NOx in Zürich per Year [ppb]",
        xlab = "Year", ylab = "ppb")

# Boxplots for NOx per monitoring station
air.he <- air %>% filter(Standort == "Zch_Heubeeribüel")
air.ro <- air %>% filter(Standort == "Zch_Rosengartenstrasse")
air.sc <- air %>% filter(Standort == "Zch_Schimmelstrasse")
air.st <- air %>% filter(Standort == "Zch_Stampfenbachstrasse")

boxplot(Wert ~ Jahr, data = air.he, subset = Parameter %in% names(table("NOx")),
        main= "NOx at Heubeeribuel per Year [ppb]",
        xlab = "Year", ylab = "ppb")

boxplot(Wert ~ Jahr, data = air.ro, subset = Parameter %in% names(table("NOx")),
        main= "NOx at Rosengartenstrasse per Year [ppb]",
        xlab = "Year", ylab = "ppb")

boxplot(Wert ~ Jahr, data = air.sc, subset = Parameter %in% names(table("NOx")),
        main= "NOx at Schimmelstrasse per Year [ppb]",
        xlab = "Year", ylab = "ppb")

boxplot(Wert ~ Jahr, data = air.st, subset = Parameter %in% names(table("NOx")),
        main= "NOx at Stampfenbachstrasse per Year [ppb]",
        xlab = "Year", ylab = "ppb")

# bar chart pflanzjahr alle
ggplot(d.trees, aes(x = pflanzjahr)) +
  geom_bar() +
  labs(title="Trees per year planted")
## Warning: Removed 13987 rows containing non-finite values (`stat_count()`).

# bar chart nur neuere pflanzjahre
ggplot(d.trees[trees$pflanzjahr > 1949, ], aes(x = pflanzjahr)) +
  geom_bar() +
  labs(title="Trees planted as of 1950")

# bar chart kronendurchmesser
ggplot(d.trees, aes(x = kronendurchmesser)) +
  geom_bar() +
  labs(title="Number of trees per crown diameter")

As one can see there is a trend to planting more trees in Zürich. However, there are also quite a few outliers visible in the graph. These outliers can usually be explained quite easily with replanting efforts. For example in 2000 a larger number of trees than normal were planted as replacements for all the trees that were blown down or had to be cut down because of cyclone Lothar in December of 1999.

1.8 Analysis

Having gained an overview of the data, we would now like to analyse the data in more detail using a few different methodologies.

1.8.1 Timeseries Analysis

In this section we are trying to see if there is a correlation over time between the amount of trees and the air quality or temperature. For this we use timeseries analysis, meaning we need to convert our data into timeseries objects. After transforming them we can then look at the decomposition of the objects. Thus we are able to see trends, seasonality and residuals. However the seasonality is only visible for air pollution and temperature, as the tree information is only available on a yearly basis.

meteo %<>% complete(Date=seq.Date(min(Date), max(Date), by='day'))

# Use the time series class of the library stats
freq_daily <- 365.2422
temp <-
  ts(meteo$T, start=c(year(min(meteo$Date)),yday(min(meteo$Date))),
     frequency=freq_daily) %>%
  na_replace(fill=0)

# Stationarity test and decomposition
# adf.test(temp,k=0)
temp_comp=decompose(temp)
plot(temp_comp)
title(sub = "Temperature")

# Manual decomposition
meteo %<>% mutate(year=year(meteo$Date)+yday(meteo$Date)/freq_daily)
temp_trend <- lm(meteo$T~meteo$year)
plot(temp, main="Temperature trend per year")
abline(temp_trend)

# Prepare yearly data

meteo_yr <- meteo %>%
  mutate(temp_raw=replace_na(T,0)) %>%
  group_by(Year=year(Date)) %>%
  filter(Year>=1980 & Year<=2021) %>%
  summarize(temp=mean(temp_raw)) %>%
  ungroup()


temp_yr <- ts(temp, start=min(meteo_yr$Year))
tb_temp_ts <- tbats(temp_yr)

# Differ
## twice-difference the CO2 data
temp_d2 <- diff(temp, differences = 1)
## plot the differenced data
# plot(temp_d2, ylab = "Temperature without trend")

## difference the differenced CO2 data
temp_d2d12 <- diff(temp_d2, lag = 12)
## plot the newly differenced data
plot(temp_d2d12, ylab = "Temperature without trend and seasonality")

Generally we can see that the temperature is slightly rising over time. There is a slight upwards trend noticeable and it is also important to remember how much danger a temperature increase of just one percent can be for the biodiversity.

air.short %<>% complete(Date=seq.Date(min(Date), max(Date), by='day'))

# Use the time series class of the library stats
freq_daily <- 365.2422
co <-
  ts(air.short$CO, start=c(year(min(air.short$Date)),yday(min(air.short$Date))),
     frequency=freq_daily) %>%
  na_replace(fill=0)
NOx <-
  ts(air.short$NOx, start=c(year(min(air.short$Date)), yday(min(air.short$Date))),
     frequency=freq_daily) %>%
  na_replace(fill=0)

# Stationarity test and decomposition
# adf.test(co,k=0)
# adf.test(NOx,k=0)
co_comp=decompose(co)
NOx_comp=decompose(NOx)
# plot(co_comp)
# title(sub = "CO")
# plot(NOx_comp)
# title(sub = "NOx")


# Manual decomposition
air.short %<>% mutate(year=year(air.short$Date)+yday(air.short$Date)/freq_daily)
co_trend <- lm(air.short$CO~air.short$year)
NOx_trend <- lm(air.short$NOx~air.short$year)
# plot(co, main="CO trend per year")
# abline(co_trend)
# plot(NOx, main="NOx trend per year")
# abline(NOx_trend)

air_yr <- air.short %>%
  mutate(co_raw=replace_na(CO,0), NOx_raw=replace_na(NOx,0)) %>%
  group_by(Year=year(Date)) %>%
  filter(Year>=1980 & Year<=2021) %>%
  summarize(co=sum(co_raw), NOx=mean(NOx_raw)) %>%
  ungroup()

# Time series
co_yr <- ts(air_yr$co, start=min(air_yr$Year), frequency=1)
NOx_yr <- ts(air_yr$NOx, start=min(air_yr$Year), frequency=1)

# plot(co_yr)
# plot(NOx_yr)

# Manual decomposition
co_yr_trend <- lm(air_yr$co~air_yr$Year)
plot(co_yr, xlab='Year', ylab='Average co pollution')
abline(co_yr_trend)
title(main = "CO development over the years and trend line")

NOx_yr_trend <- lm(air_yr$NOx~air_yr$Year)
plot(NOx_yr, xlab='Year', ylab='Average NOx pollution')
abline(NOx_yr_trend)
title(main = "NOx development over the years and trend line")

# plot(co_yr)
# pacf(co_yr)
# plot(tbats(co_yr))
# title(sub = "CO ")
tree_ts <-  ts(tree_ts_sum$sum_trees, start=min(tree_ts_sum$pflanzjahr), frequency=1)
tb_tree_ts <- tbats(tree_ts)
tb_co_ts <- tbats(co_yr)
tb_nox_ts <- tbats(NOx_yr)

plot(residuals(tb_co_ts))
title(main = "Residuals of CO")

plot(residuals(tb_nox_ts))
title(main = "Residuals of NOx")

# adf.test(co_yr)

# "Forecast"
# plot(forecast(co_yr))

The timeseries analysis of Carbon monoxide (co) and Nitrogen oxide (NOx) show that the they are closely correlated. It is further clear that they have both decreased drastically since the 1980 in Zürich. It is unlikely that the whole change can be attributed to the growing number of trees and green spaces in Zürich. It is more likely that a variety of factors including advancement in technologies and changes in laws and regulations contributed as well to the improvement in air quality.

# Make the time series comparable
temp_comp_random <- data.frame(Date=time(temp_comp$random), Random=temp_comp$random)
co_comp_random <- data.frame(Date=time(co_comp$random), Random=co_comp$random)
NOx_comp_random <- data.frame(Date=time(NOx_comp$random), Random=NOx_comp$random)
#trees_comp_random <- data.frame(Date=time(trees_comp$random), Random=trees_comp$random)


window <- list(start=1980,end=2021)

temp_comp_random %<>% filter(Date>=window$start&Date<window$end)
co_comp_random %<>% filter(Date>=window$start&Date<window$end)
NOx_comp_random %<>% filter(Date>=window$start&Date<window$end)
#trees_comp_random %<>% filter(Date>=window$start&Date<window$end)

temp_comp_random_ts <- ts(temp_comp_random$Random, start=c(window$start,1), frequency=freq_daily)
co_comp_random_ts <- ts(co_comp_random$Random, start=c(window$start,1), frequency=freq_daily)
NOx_comp_random_ts <- ts(NOx_comp_random$Random, start=c(window$start,1), frequency=freq_daily)
#trees_comp_random_ts <- ts(trees_comp_random$Random, start=c(window$start,1), frequency=freq_daily)


# Cross correlation function
# ccf(temp_comp_random_ts,co_comp_random_ts)

# ccf(temp_comp_random_ts, co_comp_random_ts, 
#     lag.max = 300,
#     main = "Temp - CO Cross-Correlation Plot",
#     ylab = "CCF", 
#     na.action = na.pass)

ccf(residuals(tb_tree_ts), residuals(tb_nox_ts), 
    lag.max = 300,
    main = "Trees - NOx Cross-Correlation Plot",
    ylab = "CCF")

ccf(residuals(tb_tree_ts), residuals(tb_co_ts), 
    lag.max = 300,
    main = "Trees - CO Cross-Correlation Plot",
    ylab = "CCF")

ccf(residuals(tb_tree_ts), residuals(tb_temp_ts), 
    lag.max = 300,
    main = "Trees - Temperature Cross-Correlation Plot",
    ylab = "CCF")

Now one can see the correlations between the sum of trees and air quality (CO and NOx) as well as the correlation between the sum of trees and temperature. The graphs shows no strong correlations, although a slightly significant correlation with a lag is visible for amount of trees on air quality. Meaning that after a some time a larger amount of trees could have an influence in reducing Carbon monoxide and Nitrogen oxide in the air.

1.10 Conclusions and findings

1.11 Outlook and next steps